"""
@author: ZY
@Time: 2021/10/07
"""
from Script.swggerApi import SwaggerApi


class Interfaces:
    """
    用于获取swagger地址的所有接口并将它们变成[{path:描述},{path:描述}...]的列表字典形式
    """
    def interfaces(self):
        resp = SwaggerApi.swagger()
        paths = resp['paths']
        interface_list = []
        for k in paths:
            if 'post' in paths[k]:
                interface_list.append(
                    {
                        str(k): str(paths[k]['post']['tags'][0]) + "-" + str(paths[k]['post']['summary']),
                        "title": str(paths[k]['post']['tags'][0]) + "-" + str(paths[k]['post']['summary'])
                    }
                )
            # if 'get' in paths[k]:
            #     interface_list.append(
            #         {
            #             str(k): str(paths[k]['get']['tags'][0]) + "-" + str(paths[k]['get']['summary']),
            #             "title": str(paths[k]['get']['tags'][0]) + "-" + str(paths[k]['get']['summary'])
            #         }
            #     )
        return interface_list


Interfaces = Interfaces()

if __name__ == '__main__':
    res = Interfaces.interfaces()
    print(res)
